From 9c69884355fe6eebf1a59144e5b195620a8926bc Mon Sep 17 00:00:00 2001 From: oliskoli Date: Thu, 7 Dec 2006 19:29:51 +0000 Subject: [PATCH] Add a function which extracts the filename portion from given full name. --- defs.h | 2 ++ util.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/defs.h b/defs.h index 8bb8f16cd..ab2024f95 100644 --- a/defs.h +++ b/defs.h @@ -726,6 +726,8 @@ char * convert_human_date_format(const char *human_datef); /* "MM,YYYY,DD" -> "% char * convert_human_time_format(const char *human_timef); /* "HH+mm+ss" -> "%H+%M+%S" */ char * pretty_deg_format(double lat, double lon, char fmt, int html); /* decimal -> dd.dddd or dd mm.mmm or dd mm ss */ +char * get_filename(const char *fname); /* extract the filename portion */ + /* * Character encoding transformations. */ diff --git a/util.c b/util.c index 1fabfe0c0..c0debfcc8 100644 --- a/util.c +++ b/util.c @@ -1627,3 +1627,17 @@ char *xml_attribute( xml_tag *tag, char *attrname ) } return result; } + +char *get_filename(const char *fname) +{ + char *res, *cb, *cs; + + cb = strrchr(fname, '\\'); + cs = strrchr(fname, '/'); + + if (cb == NULL) res = cs; + else if (cs == NULL) res = cb; + else res = (cs > cb) ? cs : cb; + + return (res == NULL) ? (char *) fname : ++res; +} -- 2.30.2